import type { MultipleConditionSearchSchema } from '@/components/multiple-condition-search'

export default function useConfig() {
  const searchSchema = computed<MultipleConditionSearchSchema>(() => {
    return {
      placeholder: '默认按照 URL 搜索',
      widgets: [
        {
          type: 'input',
          label: 'URL',
          field: 'url',
          placeholder: '请输入 URL',
        },
        {
          type: 'input',
          label: '节点名称',
          field: 'name',
          placeholder: '请输入节点名称',
        },
        {
          type: 'input',
          label: '规则 ID',
          field: 'waf_id',
          message: '规则 ID 格式不正确',
          validate: validateRuleID,
          placeholder: '请输入规则 ID',
        },
        {
          type: 'input',
          label: '规则名称',
          field: 'waf_name',
          placeholder: '请输入规则名称',
        },
        {
          type: 'select',
          label: '规则类型',
          field: 'module',
          placeholder: '请选择规则类型',
          options: [
            { label: '自定义规则', value: 1 },
            { label: '速率限制', value: 2 },
            { label: '白名单', value: 3 },
          ],
        },
        {
          type: 'input',
          label: '请求 IP',
          field: 'ip',
          placeholder: '请输入请求 IP',
        },
        // {
        //   type: 'input',
        //   label: '请求地区',
        //   field: 'rep_region',
        //   placeholder: '请输入请求地区',
        // },
        {
          type: 'select',
          label: '请求方法',
          field: 'method',
          placeholder: '请输入请求方法',
          options: [
            { label: 'GET', value: 'get' },
            { label: 'POST', value: 'post' },
            { label: 'DELETE', value: 'delete' },
            { label: 'PUT', value: 'put' },
            { label: 'OPTIONS', value: 'options' },
            { label: 'CONNECT', value: 'connect' },
            { label: 'HEAD', value: 'head' },
            { label: 'TRACE', value: 'trace' },
            { label: 'PATCHS', value: 'patchs' },
          ],
        },
        // {
        //   type: 'select',
        //   label: '请求方法',
        //   field: 'waf_name',
        //   placeholder: '请选择请求方法',
        //   options: [
        //     { label: 'GET', value: 'GET' },
        //   ],
        // },
      ],
    }
  })

  const tableColumns = buildColumns([
    {
      title: '命中时间',
      dataIndex: 'time',
      format: 'date-time',
      width: 160,
      sortable: sortableSettings,
    },
    {
      title: '请求 IP (地区)',
      dataIndex: 'rep_region',
      slotName: 'rep_region',
      width: 200,
      // format: 'copy'
    },
    {
      title: 'URL',
      dataIndex: 'url',
      slotName: 'url',
      width: 360,
      // format: 'copy'
    },
    {
      title: '节点名称',
      dataIndex: 'name',
      slotName: 'name',
      width: 200,
    },
    // {
    //   title: '站点区域',
    //   dataIndex: 'region',
    //   slotName: 'region',
    //   width: 140
    // },
    {
      title: '节点 IP ',
      dataIndex: 'node_ip',
      slotName: 'node_ip',
      width: 140,
    },
    {
      title: '规则 ID',
      dataIndex: 'waf_id',
      slotName: 'waf_id',
      width: 200,
      // format: 'copy'
    },
    {
      title: '规则名称',
      dataIndex: 'waf_name',
      slotName: 'waf_name',
      width: 160,
    },
    {
      title: '规则类型',
      dataIndex: 'module',
      slotName: 'module',
      width: 110,
    },
    {
      title: '执行策略',
      dataIndex: 'action',
      slotName: 'action',
      width: 120,
    },
    {
      title: '请求方法',
      dataIndex: 'method',
      slotName: 'method',
      width: 100,
    },
    {
      title: 'HTTP 版本',
      dataIndex: 'http_version',
      slotName: 'http_version',
      width: 100,
    },

    {
      title: '浏览器',
      dataIndex: 'browser',
      slotName: 'browser',
      width: 100,
    },
    {
      title: '操作',
      width: 80,
      fixed: 'right',
      dataIndex: 'actions',
      slotName: 'actions',
    },
  ])

  return {
    searchSchema,
    tableColumns,
  }
}
